package com.example.allplan.Activity;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.example.allplan.R;
import com.example.allplan.StaticFangfa.IntZhuanShiJian;

public class DaoJiShiActivity extends BaseActivity {

    TextView xiaoshitextview, fenzhongtextview, miaotextview;
    int time;
    long timems;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dao_ji_shi_activity_layout);
        init();
    }

    void init() {
        time = getIntent().getIntExtra("time", -1);
        if (time == -1) Toast.makeText(this, "非法时间", Toast.LENGTH_SHORT).show();
        else timems = time * 60000 + 1000;
        xiaoshitextview = findViewById(R.id.xiaoshi_textview);
        fenzhongtextview = findViewById(R.id.fenzhong_textview);
        miaotextview = findViewById(R.id.miao_textview);
        CountDownTimer mc = new CountDownTimer(timems, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                xiaoshitextview.setText(IntZhuanShiJian.format(millisUntilFinished / 1000 / 3600));
                fenzhongtextview.setText(IntZhuanShiJian.format(millisUntilFinished / 1000 % 3600 / 60));
                miaotextview.setText(IntZhuanShiJian.format(millisUntilFinished / 1000 % 60));
            }

            @Override
            public void onFinish() {

            }
        };
        mc.start();
    }
}
